package com.dxl.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dxl.base.Result;
import com.dxl.base.Results;
import com.dxl.system.model.Config;
import com.dxl.system.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <b> 系统设置控制器
 * </b><br><br><i>Description</i> :
 * <br>Date: 2019-10-03    <br>Author : dxl
 */
@Api(value = "系统设置接口",tags = {"系统设置--接口"})
@Controller
@RequestMapping("/config")
public class ConfigController {

    @Autowired(required = false)
    private ConfigService configService;


    /**
     * <b> 插入系统设置
     * </b><br><br><i>Description</i> : 不能为空：键-config_key 值-config_value 配置名称-config_name ；不能重复：键-config_key  
     * @param config Config
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "插入系统设置",notes = "不能为空：键-config_key 值-config_value 配置名称-config_name ；不能重复：键-config_key  ")
    @RequestMapping(value = "/addOne",method = {RequestMethod.POST })
    public Result addOne(@Valid @RequestBody Config config) {
        Result result = configService.addOne(config);
        return result;
    }

    /**
     * <b> 删除系统设置
     * </b><br><br><i>Description</i> : 
     * @param configIds List: Integer
     * @return com.dxl.base.Result int
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "删除系统设置",notes = "无注意点！")
    @RequestMapping(value = "/delByIds",method = {RequestMethod.POST })
    public Result delByIds(@RequestParam(value="configIds", required = true) List<Integer> configIds){
        Result result = configService.delByIds(configIds);
        return result;
    }

    /**
     * <b> 编辑系统设置
     * </b><br><br><i>Description</i> : 不能重复：键-config_key 
     * @param config Config
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑系统设置",notes = "不能重复：键-config_key ")
    @RequestMapping(value = "/editOne",method = {RequestMethod.POST })
    public Result editOne(@Valid @RequestBody Config config) {
        Result result = configService.editOne(config);
        return result;
    }

    /**
     * <b> 编辑文件根路径
     * </b><br><br><i>Description</i> :
     * @param config2 Config
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑文件根路径",notes = "编辑文件根路径")
    @RequestMapping(value = "/editFileRootPath",method = {RequestMethod.POST })
    @ResponseBody
    public Result editFileRootPath(@Valid @RequestBody Config config2) {
        QueryWrapper<Config> wrapper = new QueryWrapper<>();
        wrapper.eq("config_key","FileRootPath");
        Config config = configService.getOne(wrapper);
        config.setConfigValue(config2.getConfigValue());
        configService.editOne(config);
        return Results.success();
    }

    /**
     * <b> 编辑默认浏览器
     * </b><br><br><i>Description</i> :
     * @param config2 Config
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑文件根路径",notes = "编辑文件根路径")
    @RequestMapping(value = "/editHtmlExePath",method = {RequestMethod.POST })
    @ResponseBody
    public Result editHtmlExePath(@Valid @RequestBody Config config2) {
        QueryWrapper<Config> wrapper = new QueryWrapper<>();
        wrapper.eq("config_key","HtmlExePath");
        Config config = configService.getOne(wrapper);
        config.setConfigValue(config2.getConfigValue());
        configService.editOne(config);
        return Results.success();
    }

    /**
     * <b> 编辑文件根路径Html
     * </b><br><br><i>Description</i> :
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑文件根路径",notes = "编辑文件根路径")
    @RequestMapping(value = "/editFileRootPathHtml",method = {RequestMethod.GET })
    public String editFileRootPathHtml(Model model) {
        Config config2 = new Config();
        config2.setConfigKey("FileRootPath");
        List<Config> configList = (List<Config>) configService.getList(config2).getData();
        Config config = configList.get(0);
        config.setConfigValue(config.getConfigValue().replace(" ",""));
        model.addAttribute(config);
        return "config/config_file_root_path_edit";
    }

    /**
     * <b> 编辑默认浏览器Html
     * </b><br><br><i>Description</i> :
     * @return com.dxl.base.Result Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑默认浏览器Html",notes = "编辑文件根路径")
    @RequestMapping(value = "/editHtmlExePathHtml",method = {RequestMethod.GET })
    public String editHtmlExePathHtml(Model model) {
        Config config2 = new Config();
        config2.setConfigKey("HtmlExePath");
        List<Config> configList = (List<Config>) configService.getList(config2).getData();
        Config config = configList.get(0);
        config.setConfigValue(config.getConfigValue().replace(" ",""));
        model.addAttribute(config);
        return "config/config_html_exe_path_edit";
    }

    /**
     * <b> ID查询系统设置
     * </b><br><br><i>Description</i> : 
     * @param configId Integer
     * @return com.dxl.base.Result: Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "ID查询系统设置",notes = "无注意点！")
    @RequestMapping(value = "/getById",method = {RequestMethod.POST })
    public Result getById(@RequestParam(value="configId", required = true) Integer configId) {
        Result result = configService.getById(configId);
        return result;
    }

    /**
     * <b> 条件查询系统设置
     * </b><br><br><i>Description</i> : 
     * @param config Config
     * @return com.dxl.base.Result List: Config
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "条件查询系统设置",notes = "无注意点！")
    @RequestMapping(value = "/getList",method = {RequestMethod.POST })
    public Result getList(@Valid @RequestBody Config config) {
        Result result = configService.getList(config);
        return result;
    }

    /**
     * <b> 分页条件查询系统设置
     * </b><br><br><i>Description</i> : 
     * @param config Config, currentPage -Integer
     * @return com.dxl.base.Result List: Config
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "分页条件查询系统设置",notes = "无注意点！")
    @RequestMapping(value = "/getListByPage",method = {RequestMethod.POST })
    public Result getListByPage(@Valid @RequestBody Config config, @RequestParam(value="currentPage", required = false, defaultValue = "1") Integer currentPage, @RequestParam(value="pageSize", required = false, defaultValue = "20") Integer pageSize) {
        Result result = configService.getListByPage(config, currentPage, pageSize);
        return result;
    }

    /**
     * <b> 系统设置能否新增
     * </b><br><br><i>Description</i> : 无权限限制；不能为空：键-config_key 值-config_value 配置名称-config_name ；不能重复：键-config_key  
     * @param config Config
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "系统设置能否新增",notes = "无权限限制；不能为空：键-config_key 值-config_value 配置名称-config_name ；不能重复：键-config_key  ")
    @RequestMapping(value = "/isAddable",method = {RequestMethod.POST })
    public Result isAddable(@Valid @RequestBody Config config) {
        Result result = configService.isConfigAddable(config);
        return result;
    }

    /**
     * <b> 系统设置能否编辑
     * </b><br><br><i>Description</i> : 无权限限制；不能重复：键-config_key 
     * @param config Config
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "系统设置能否编辑",notes = "无权限限制；不能重复：键-config_key ")
    @RequestMapping(value = "/isEditable",method = {RequestMethod.POST })
    public Result isEditable(@Valid @RequestBody Config config) {
        Result result = configService.isConfigEditable(config);
        return result;
    }
}
